package middleware

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"micro-server/public"
	"runtime/debug"
)

func Error(c *gin.Context) {
	//监控服务挂掉的内容
	defer func() {
		r := c.Errors.String()
		if r != "" {
			public.ContextError(c, "【ERROR】", map[string]interface{}{
				"标题": fmt.Sprintf(r),
				"内容": string(debug.Stack()),
			})
			//打印错误堆栈信息
			//debug.PrintStack()
			c.Abort()
		}
	}()
	c.Next()
}
